#=============================================================================
'''
    Centura Module

    Centura uses a weird file structure that is mostly ascii, but
    combines binary, and has funny line structure.

'''
#=============================================================================
# Copyright 2004-2012, Matt Peloquin and Construx. This file is part of Code
# Surveyor, covered under GNU GPL v3 and is distributed WITHOUT ANY WARRANTY.
#=============================================================================
import re
import string
from Code import Code
from framework import utils

class customCentura( Code ):
    '''

    '''

    def _cs_init_config_options(self):
        super(customCentura, self)._cs_init_config_options()

        # Override comments for Centura specifics
        self.singleLineComments = [ re.compile(r"^\s*!") ]
        self.reBlankLine = re.compile(r''' ^ \s* $ ''', self._reFlags)

        self.reBinary = re.compile(r''' ^ [0-9] ''', self._reFlags)



    def _alternate_line_processing(self, line):
        '''
        Skip lines that don't start with code phrase
        '''
        if self.reBinary.match(line):
            return True

        codeWords = [
            '!',
            'form window: ',
            'class: ',
            'function: ',
            'number: ',
            'string: ',
            'if',
            'else',
            'set',
            'on ',
            'while ',
            'call ',
            'return ',
            ]
        if line.startswith('.'):
            code = line[11:].lower().strip()
            if not any([code.startswith(word) for word in codeWords]):
                return True


    def _preprocess_line(self, rawLine):
        line = super(customCentura, self)._preprocess_line(rawLine)

        # Whack off the start of the head lines
        if line.startswith('.'):
            line = line[11:]

        return line

